package com.ruoyi.user.service.impl;

import com.ruoyi.user.domain.User;
import com.ruoyi.user.mapper.UserMapper;
import com.ruoyi.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceeImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public String login(User user) {
        String password=userMapper.selectUserMessage(user.getUsername());

        if(password.equals(user.getPassword())){
            return "登录成功";
        }
        else{
            return "登录失败";
        }
    }

    @Override
    public String register(User user) {
        // 查询用户名是否存在
        int exists = userMapper.selectUserName(user.getUsername());
        if (exists > 0) {
            return "用户已存在";
        }

        // 插入用户
        int res = userMapper.insertUser(user);
        if (res == 1) {
            return "注册成功";
        } else {
            return "注册失败";
        }
    }
}
